#coding:utf8
"""

"""
from utils.database import DataServer
from datetime import datetime
from utils.tools import get_all_trade_days
import pandas as pd


def run():
    db = DataServer()
    t1 = datetime.today()
    all_trade_days = get_all_trade_days()
    today = t1.strftime("%Y-%m-%d")
    last_day = all_trade_days[all_trade_days.index(today) - 1]
    today = '2022-12-15'
    last_day = '2022-12-14'
    cmd = f"""select * from hangqing where date in ("{today}", "{last_day}") """
    db._db_connect()
    db.cursor.execute(cmd)
    t3 = db.cursor.fetchall()
    col_name = ["id","stock_code","stock_name","date","close_price","max_price","min_price","open_price","close_price_p1","zde","zdf","hsl","cjl","cjje","zsz","ltsz","zljlr","zljzb"]
    df = pd.DataFrame(data=t3, columns=col_name)
    df2 = df.sort_values(['stock_code', 'date'], ascending=[True, False])
    db._db_close()

    codes = list(df2['stock_code'].values)
    dfs = []
    for code in codes:
        t1 = df2[df2['stock_code'] == code]
        if len(t1) < 2:
            continue
        if (t1['close_price'].iloc[0] > t1['close_price'].iloc[1]) and (t1['cjl'].iloc[0] > t1['cjl'].iloc[1]):
            dfs.append(t1)

    df2 = pd.concat(dfs)
    print()



if __name__=="__main__":
    run()
